﻿using ST.Torch.WebApi.Core.Entities.DaTi;
using System.Linq.Expressions;



namespace ST.Torch.WebApi.Application.DaTi.Services
{
    public class D_TiMuService : ID_TiMuService, ITransient
	{
		private readonly IRepository<D_TiMu> _repository;

        public D_TiMuService(IRepository<D_TiMu> D_TiMuRepository)
		{
			_repository = D_TiMuRepository;
		}

		#region curd
		public  void Insert(D_TiMu entity)
		{
			 _repository.Insert(entity);
		}
		public async Task InsertAsync(D_TiMu entity, string[] Includes=null)
		{
				await _repository.InsertAsync(entity);
			
		}
		public void Update(D_TiMu entity, string[] Includes = null)
		{
			if (Includes == null)
				 _repository.Update(entity);
			else
				 _repository.UpdateInclude(entity, Includes);
		
		}
		public async Task UpdateAsync(D_TiMu entity, string[] Includes = null)
		{ 
			if (Includes == null)
				await _repository.UpdateAsync(entity);
			else
				await _repository.UpdateIncludeAsync(entity, Includes);
		}
		public void Delete(D_TiMu entity, bool IsSoft=false)
		{
			_repository.Delete(entity);
		}
		public async Task DeleteAsync(D_TiMu entity, bool IsSoft = false)
		{
			await _repository.DeleteAsync(entity);
		}
        public bool Any(Expression<Func<D_TiMu, bool>> predicate)
        {
            return _repository.Any(predicate);
        }
        public async Task<bool> AnyAsync(Expression<Func<D_TiMu, bool>> predicate)
        {
            return await _repository.AnyAsync(predicate);
        }
        public D_TiMu Single(Expression<Func<D_TiMu, bool>> predicate, bool tracking = false)
		{
			return _repository.SingleOrDefault(predicate, tracking);

		}
		public async Task<D_TiMu> SingleAsync(Expression<Func<D_TiMu, bool>> predicate, bool tracking = false)
		{
			
			return await _repository.SingleOrDefaultAsync(predicate, tracking);

		}
		public List<D_TiMu> Query(Expression<Func<D_TiMu, bool>> predicate, bool tracking = false)
		{
            return  _repository.AsQueryable(tracking).Where(predicate).OrderByDescending(u => u.CreateTime).ToList();
		}
		public async Task<List<D_TiMu>> QueryAsync(Expression<Func<D_TiMu, bool>> predicate, bool tracking = false)
		{
			return await _repository.Where(predicate, tracking).OrderByDescending(u => u.CreateTime).ToListAsync();
		}

		public PagedList<D_TiMu> QueryPage(Expression<Func<D_TiMu, bool>> predicate, PageReq page, bool tracking = false)
		{
			return _repository.Where(predicate, tracking).OrderByDescending(u => u.CreateTime).ToPagedList(page.page, page.limit);
		}
		public  async Task<PagedList<D_TiMu>> QueryPageAsync(Expression<Func<D_TiMu, bool>> predicate, PageReq page, bool tracking = false)
		{
			return await _repository.Where(predicate, tracking).OrderByDescending(u => u.CreateTime).ToPagedListAsync(page.page, page.limit);
		}




        #endregion
   



    }
}
